package com.example.myapplication9_4;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private TextView txt_uName;
    private Button btn_toLogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        txt_uName = findViewById(R.id.txt_uName);
        btn_toLogin = findViewById(R.id.btn_toLogin);


        btn_toLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, LoginActivity.class);
                startActivityForResult(intent, 1);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        ImageView useImage = findViewById(R.id.user_image);
        if (requestCode == 1 && resultCode == RESULT_OK) {
            String uName = data.getStringExtra("uName");
            if (!uName.isEmpty()) {
                txt_uName.setText("姓名: " + uName);
                useImage.setImageResource(R.drawable.p3);
            }
        }
    }
}